package com.example.springbootdemo.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TokenInterceptor extends HandlerInterceptorAdapter {

    private String token = "";

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        token = request.getHeader("Authorization");
        if (token == null) {
            response.sendRedirect(request.getContextPath() + "/user/logout");
            return false;
        }
        return true;
    }
}
